﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Data.Common;

namespace Chenxin.Lib.House.DAL
{
    /// <summary>
    /// 数据访问类House_BaseInfo。
    /// </summary>
    public class House_BaseInfo
    {
        private const string CONNECTSTRING_SEARCH = "Chenxin_House_Search";
        private const string CONNECTSTRING = "Chenxin_House";

        public House_BaseInfo()
        { }
        #region  成员方法

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public static bool Exists(Guid HouseId)
        {
            Database db = DatabaseFactory.CreateDatabase(CONNECTSTRING);
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from House_BaseInfo where HouseId=@HouseId ");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "HouseId", DbType.Guid, HouseId);
            int cmdresult;
            object obj = db.ExecuteScalar(dbCommand);
            if ((Object.Equals(obj, null)) || (Object.Equals(obj, System.DBNull.Value)))
            {
                cmdresult = 0;
            }
            else
            {
                cmdresult = int.Parse(obj.ToString());
            }
            if (cmdresult == 0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }

        /// <summary>
        /// 判断记录是否存在根据查询条件
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        public static bool Exists(string where)
        {
            Database db = DatabaseFactory.CreateDatabase(CONNECTSTRING);
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select HouseId from House_BaseInfo where "+where);
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());

            DataSet ds = db.ExecuteDataSet(CommandType.Text, strSql.ToString());

            if (ds.Tables.Count > 0)
            {
                if (ds.Tables[0].Rows.Count>0)
                {
                    return true;
                }
            }
            return false;
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public static void Add(Chenxin.Lib.House.Entity.House_BaseInfo model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into House_BaseInfo(");
            strSql.Append("HouseId,CityId,HouseCode,CommunityId,Community,BuildingId,BuildingName,Room,Address,Region,Block,CompleteYear,CustomerId,CustomerName,BuildingArea,HouseUse,BuildingType,Model_Room,CompanyId,CompanyName,Model_Hall,Model_Toilet,Model_Balcony,Total_Floor,Cur_Floor,Fitment,Direction,SalePrice_T,SalePrice_U,SalePrice_R,RentPrice,RentPrice_R,HavRentContract,PayMode,IsGroup,BaseEquip,OtherEquip,Status,Adddate,AddPersonId,AddPerson,AddDepartId,AddDepart,OprPersonId,OprPerson,OprDepartId,OprDepart,IsProtectPhone,DisplayPhone,IsProtectHouse,IsAutoProPhone,IsAutoProHouse,UpdateTime,ServiceTime,IsHot,IsHavekey,IsTrust,IsMarked,MarkCode,IsNeedTran,RequestNum,InfoSource,Actuality,BusinessKind,Property,TraceNum,HitNum,Remarks,IsHideHouse,DetailAddress,HouseBlock)");

            strSql.Append(" values (");
            strSql.Append("@HouseId,@CityId,@HouseCode,@CommunityId,@Community,@BuildingId,@BuildingName,@Room,@Address,@Region,@Block,@CompleteYear,@CustomerId,@CustomerName,@BuildingArea,@HouseUse,@BuildingType,@Model_Room,@CompanyId,@CompanyName,@Model_Hall,@Model_Toilet,@Model_Balcony,@Total_Floor,@Cur_Floor,@Fitment,@Direction,@SalePrice_T,@SalePrice_U,@SalePrice_R,@RentPrice,@RentPrice_R,@HavRentContract,@PayMode,@IsGroup,@BaseEquip,@OtherEquip,@Status,@Adddate,@AddPersonId,@AddPerson,@AddDepartId,@AddDepart,@OprPersonId,@OprPerson,@OprDepartId,@OprDepart,@IsProtectPhone,@DisplayPhone,@IsProtectHouse,@IsAutoProPhone,@IsAutoProHouse,@UpdateTime,@ServiceTime,@IsHot,@IsHavekey,@IsTrust,@IsMarked,@MarkCode,@IsNeedTran,@RequestNum,@InfoSource,@Actuality,@BusinessKind,@Property,@TraceNum,@HitNum,@Remarks,@IsHideHouse,@DetailAddress,@HouseBlock)");
            Database db = DatabaseFactory.CreateDatabase(CONNECTSTRING);
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "HouseId", DbType.Guid, model.HouseId);
            db.AddInParameter(dbCommand, "CityId", DbType.Guid, model.CityId);
            db.AddInParameter(dbCommand, "HouseCode", DbType.AnsiString, model.HouseCode);
            db.AddInParameter(dbCommand, "CommunityId", DbType.Guid, model.CommunityId);
            db.AddInParameter(dbCommand, "Community", DbType.AnsiString, model.Community);
            db.AddInParameter(dbCommand, "BuildingId", DbType.Guid, model.BuildingId);
            db.AddInParameter(dbCommand, "BuildingName", DbType.AnsiString, model.BuildingName);
            db.AddInParameter(dbCommand, "Room", DbType.AnsiString, model.Room);
            db.AddInParameter(dbCommand, "Address", DbType.AnsiString, model.Address);
            db.AddInParameter(dbCommand, "Region", DbType.AnsiString, model.Region);
            db.AddInParameter(dbCommand, "Block", DbType.AnsiString, model.Block);
            db.AddInParameter(dbCommand, "CompleteYear", DbType.Int32, model.CompleteYear);
            db.AddInParameter(dbCommand, "CustomerId", DbType.Guid, model.CustomerId);
            db.AddInParameter(dbCommand, "CustomerName", DbType.AnsiString, model.CustomerName);
            db.AddInParameter(dbCommand, "BuildingArea", DbType.Double, model.BuildingArea);
            db.AddInParameter(dbCommand, "HouseUse", DbType.AnsiString, model.HouseUse);
            db.AddInParameter(dbCommand, "BuildingType", DbType.AnsiString, model.BuildingType);
            db.AddInParameter(dbCommand, "Model_Room", DbType.Int32, model.Model_Room);
            db.AddInParameter(dbCommand, "CompanyId", DbType.Guid, model.CompanyId);
            db.AddInParameter(dbCommand, "CompanyName", DbType.AnsiString, model.CompanyName);
            db.AddInParameter(dbCommand, "Model_Hall", DbType.Int32, model.Model_Hall);
            db.AddInParameter(dbCommand, "Model_Toilet", DbType.Int32, model.Model_Toilet);
            db.AddInParameter(dbCommand, "Model_Balcony", DbType.Int32, model.Model_Balcony);
            db.AddInParameter(dbCommand, "Total_Floor", DbType.Int32, model.Total_Floor);
            db.AddInParameter(dbCommand, "Cur_Floor", DbType.Int32, model.Cur_Floor);
            db.AddInParameter(dbCommand, "Fitment", DbType.AnsiString, model.Fitment);
            db.AddInParameter(dbCommand, "Direction", DbType.AnsiString, model.Direction);
            db.AddInParameter(dbCommand, "SalePrice_T", DbType.Decimal, model.SalePrice_T);
            db.AddInParameter(dbCommand, "SalePrice_U", DbType.Decimal, model.SalePrice_U);
            db.AddInParameter(dbCommand, "SalePrice_R", DbType.Decimal, model.SalePrice_R);
            db.AddInParameter(dbCommand, "RentPrice", DbType.Decimal, model.RentPrice);
            db.AddInParameter(dbCommand, "RentPrice_R", DbType.Decimal, model.RentPrice_R);
            db.AddInParameter(dbCommand, "HavRentContract", DbType.Boolean, model.HavRentContract);
            db.AddInParameter(dbCommand, "PayMode", DbType.AnsiString, model.PayMode);
            db.AddInParameter(dbCommand, "IsGroup", DbType.Boolean, model.IsGroup);
            db.AddInParameter(dbCommand, "BaseEquip", DbType.AnsiString, model.BaseEquip);
            db.AddInParameter(dbCommand, "OtherEquip", DbType.AnsiString, model.OtherEquip);
            db.AddInParameter(dbCommand, "Status", DbType.Int32, model.Status);
            db.AddInParameter(dbCommand, "Adddate", DbType.DateTime, model.Adddate);
            db.AddInParameter(dbCommand, "AddPersonId", DbType.Guid, model.AddPersonId);
            db.AddInParameter(dbCommand, "AddPerson", DbType.AnsiString, model.AddPerson);
            db.AddInParameter(dbCommand, "AddDepartId", DbType.Guid, model.AddDepartId);
            db.AddInParameter(dbCommand, "AddDepart", DbType.AnsiString, model.AddDepart);
            db.AddInParameter(dbCommand, "OprPersonId", DbType.Guid, model.OprPersonId);
            db.AddInParameter(dbCommand, "OprPerson", DbType.AnsiString, model.OprPerson);
            db.AddInParameter(dbCommand, "OprDepartId", DbType.Guid, model.OprDepartId);
            db.AddInParameter(dbCommand, "OprDepart", DbType.AnsiString, model.OprDepart);
            db.AddInParameter(dbCommand, "IsProtectPhone", DbType.Boolean, model.IsProtectPhone);
            db.AddInParameter(dbCommand, "DisplayPhone", DbType.AnsiString, model.DisplayPhone);
            db.AddInParameter(dbCommand, "IsProtectHouse", DbType.Boolean, model.IsProtectHouse);
            db.AddInParameter(dbCommand, "IsAutoProPhone", DbType.Boolean, model.IsAutoProPhone);
            db.AddInParameter(dbCommand, "IsAutoProHouse", DbType.Boolean, model.IsAutoProHouse);
            db.AddInParameter(dbCommand, "UpdateTime", DbType.DateTime, model.UpdateTime);
            db.AddInParameter(dbCommand, "ServiceTime", DbType.DateTime, model.ServiceTime);
            db.AddInParameter(dbCommand, "IsHot", DbType.Boolean, model.IsHot);
            db.AddInParameter(dbCommand, "IsHavekey", DbType.Boolean, model.IsHavekey);
            db.AddInParameter(dbCommand, "IsTrust", DbType.Boolean, model.IsTrust);
            db.AddInParameter(dbCommand, "IsMarked", DbType.Boolean, model.IsMarked);
            db.AddInParameter(dbCommand, "MarkCode", DbType.AnsiString, model.MarkCode);
            db.AddInParameter(dbCommand, "IsNeedTran", DbType.Boolean, model.IsNeedTran);
            db.AddInParameter(dbCommand, "RequestNum", DbType.Int32, model.RequestNum);
            db.AddInParameter(dbCommand, "InfoSource", DbType.AnsiString, model.InfoSource);
            db.AddInParameter(dbCommand, "Actuality", DbType.AnsiString, model.Actuality);
            db.AddInParameter(dbCommand, "BusinessKind", DbType.Int32, model.BusinessKind);
            db.AddInParameter(dbCommand, "Property", DbType.AnsiString, model.Property);
            db.AddInParameter(dbCommand, "TraceNum", DbType.Int32, model.TraceNum);
            db.AddInParameter(dbCommand, "HitNum", DbType.Int32, model.HitNum);
            db.AddInParameter(dbCommand, "Remarks", DbType.AnsiString, model.Remarks);
            db.AddInParameter(dbCommand, "IsHideHouse", DbType.Boolean, model.IsHideHouse);
            db.AddInParameter(dbCommand, "DetailAddress", DbType.AnsiString, model.DetailAddress);
            db.AddInParameter(dbCommand, "HouseBlock", DbType.AnsiString, model.HouseBlock);
            db.ExecuteNonQuery(dbCommand);
        }



        /// <summary>
        /// 更新房源区域，板块，片区信息
        /// </summary>
        /// <param name="communityId"></param>
        public static void UpdateHouseRBA(Guid communityId,string region,string block,string houseBlock)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update House_BaseInfo set ");
            strSql.Append("Region=@Region,");
            strSql.Append("Block=@Block,");
            strSql.Append("HouseBlock=@HouseBlock");
            strSql.Append(" where CommunityId=@CommunityId ");
            Database db = DatabaseFactory.CreateDatabase(CONNECTSTRING);
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "Region", DbType.AnsiString, region);
            db.AddInParameter(dbCommand, "Block", DbType.AnsiString, block);
            db.AddInParameter(dbCommand, "HouseBlock", DbType.AnsiString, houseBlock);
            db.AddInParameter(dbCommand, "CommunityId", DbType.Guid, communityId);
            db.ExecuteNonQuery(dbCommand);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public static void UpdateMarkedInfo(Guid houseId, string code, bool isMarked)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update House_BaseInfo set ");
            strSql.Append("IsMarked=@IsMarked,");
            strSql.Append("MarkCode=@MarkCode ");
            strSql.Append("where HouseId=@HouseId ");
            Database db = DatabaseFactory.CreateDatabase(CONNECTSTRING);
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "HouseId", DbType.Guid, houseId);
            db.AddInParameter(dbCommand, "IsMarked", DbType.Boolean, isMarked);
            db.AddInParameter(dbCommand, "MarkCode", DbType.AnsiString, code);
            db.ExecuteNonQuery(dbCommand);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public static void Update(Chenxin.Lib.House.Entity.House_BaseInfo model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update House_BaseInfo set ");
            strSql.Append("CityId=@CityId,");
            strSql.Append("HouseCode=@HouseCode,");
            strSql.Append("CommunityId=@CommunityId,");
            strSql.Append("Community=@Community,");
            strSql.Append("BuildingId=@BuildingId,");
            strSql.Append("BuildingName=@BuildingName,");
            strSql.Append("Room=@Room,");
            strSql.Append("Address=@Address,");
            strSql.Append("Region=@Region,");
            strSql.Append("Block=@Block,");
            strSql.Append("CompleteYear=@CompleteYear,");
            strSql.Append("CustomerId=@CustomerId,");
            strSql.Append("CustomerName=@CustomerName,");
            strSql.Append("BuildingArea=@BuildingArea,");
            strSql.Append("HouseUse=@HouseUse,");
            strSql.Append("BuildingType=@BuildingType,");
            strSql.Append("Model_Room=@Model_Room,");
            strSql.Append("CompanyId=@CompanyId,");
            strSql.Append("CompanyName=@CompanyName,");
            strSql.Append("Model_Hall=@Model_Hall,");
            strSql.Append("Model_Toilet=@Model_Toilet,");
            strSql.Append("Model_Balcony=@Model_Balcony,");
            strSql.Append("Total_Floor=@Total_Floor,");
            strSql.Append("Cur_Floor=@Cur_Floor,");
            strSql.Append("Fitment=@Fitment,");
            strSql.Append("Direction=@Direction,");
            strSql.Append("SalePrice_T=@SalePrice_T,");
            strSql.Append("SalePrice_U=@SalePrice_U,");
            strSql.Append("SalePrice_R=@SalePrice_R,");
            strSql.Append("RentPrice=@RentPrice,");
            strSql.Append("RentPrice_R=@RentPrice_R,");
            strSql.Append("HavRentContract=@HavRentContract,");
            strSql.Append("PayMode=@PayMode,");
            strSql.Append("IsGroup=@IsGroup,");
            strSql.Append("BaseEquip=@BaseEquip,");
            strSql.Append("OtherEquip=@OtherEquip,");
            strSql.Append("Status=@Status,");
            strSql.Append("Adddate=@Adddate,");
            strSql.Append("AddPersonId=@AddPersonId,");
            strSql.Append("AddPerson=@AddPerson,");
            strSql.Append("AddDepartId=@AddDepartId,");
            strSql.Append("AddDepart=@AddDepart,");
            strSql.Append("OprPersonId=@OprPersonId,");
            strSql.Append("OprPerson=@OprPerson,");
            strSql.Append("OprDepartId=@OprDepartId,");
            strSql.Append("OprDepart=@OprDepart,");
            strSql.Append("IsProtectPhone=@IsProtectPhone,");
            strSql.Append("DisplayPhone=@DisplayPhone,");
            strSql.Append("IsProtectHouse=@IsProtectHouse,");
            strSql.Append("IsAutoProPhone=@IsAutoProPhone,");
            strSql.Append("IsAutoProHouse=@IsAutoProHouse,");
            strSql.Append("UpdateTime=@UpdateTime,");
            strSql.Append("ServiceTime=@ServiceTime,");
            strSql.Append("IsHot=@IsHot,");
            strSql.Append("IsHavekey=@IsHavekey,");
            strSql.Append("IsTrust=@IsTrust,");
            strSql.Append("IsMarked=@IsMarked,");
            strSql.Append("MarkCode=@MarkCode,");
            strSql.Append("IsNeedTran=@IsNeedTran,");
            strSql.Append("RequestNum=@RequestNum,");
            strSql.Append("InfoSource=@InfoSource,");
            strSql.Append("Actuality=@Actuality,");
            strSql.Append("BusinessKind=@BusinessKind,");
            strSql.Append("Property=@Property,");
            strSql.Append("TraceNum=@TraceNum,");
            strSql.Append("HitNum=@HitNum,");
            strSql.Append("Remarks=@Remarks,");
            strSql.Append("IsHideHouse=@IsHideHouse,");
            //strSql.Append("HouseBlock=@HouseBlock,");
            strSql.Append("DetailAddress=@DetailAddress");
            strSql.Append(" where HouseId=@HouseId ");
            Database db = DatabaseFactory.CreateDatabase(CONNECTSTRING);
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "HouseId", DbType.Guid, model.HouseId);
            db.AddInParameter(dbCommand, "CityId", DbType.Guid, model.CityId);
            db.AddInParameter(dbCommand, "HouseCode", DbType.AnsiString, model.HouseCode);
            db.AddInParameter(dbCommand, "CommunityId", DbType.Guid, model.CommunityId);
            db.AddInParameter(dbCommand, "Community", DbType.AnsiString, model.Community);
            db.AddInParameter(dbCommand, "BuildingId", DbType.Guid, model.BuildingId);
            db.AddInParameter(dbCommand, "BuildingName", DbType.AnsiString, model.BuildingName);
            db.AddInParameter(dbCommand, "Room", DbType.AnsiString, model.Room);
            db.AddInParameter(dbCommand, "Address", DbType.AnsiString, model.Address);
            db.AddInParameter(dbCommand, "Region", DbType.AnsiString, model.Region);
            db.AddInParameter(dbCommand, "Block", DbType.AnsiString, model.Block);
            db.AddInParameter(dbCommand, "CompleteYear", DbType.Int32, model.CompleteYear);
            db.AddInParameter(dbCommand, "CustomerId", DbType.Guid, model.CustomerId);
            db.AddInParameter(dbCommand, "CustomerName", DbType.AnsiString, model.CustomerName);
            db.AddInParameter(dbCommand, "BuildingArea", DbType.Double, model.BuildingArea);
            db.AddInParameter(dbCommand, "HouseUse", DbType.AnsiString, model.HouseUse);
            db.AddInParameter(dbCommand, "BuildingType", DbType.AnsiString, model.BuildingType);
            db.AddInParameter(dbCommand, "Model_Room", DbType.Int32, model.Model_Room);
            db.AddInParameter(dbCommand, "CompanyId", DbType.Guid, model.CompanyId);
            db.AddInParameter(dbCommand, "CompanyName", DbType.AnsiString, model.CompanyName);
            db.AddInParameter(dbCommand, "Model_Hall", DbType.Int32, model.Model_Hall);
            db.AddInParameter(dbCommand, "Model_Toilet", DbType.Int32, model.Model_Toilet);
            db.AddInParameter(dbCommand, "Model_Balcony", DbType.Int32, model.Model_Balcony);
            db.AddInParameter(dbCommand, "Total_Floor", DbType.Int32, model.Total_Floor);
            db.AddInParameter(dbCommand, "Cur_Floor", DbType.Int32, model.Cur_Floor);
            db.AddInParameter(dbCommand, "Fitment", DbType.AnsiString, model.Fitment);
            db.AddInParameter(dbCommand, "Direction", DbType.AnsiString, model.Direction);
            db.AddInParameter(dbCommand, "SalePrice_T", DbType.Decimal, model.SalePrice_T);
            db.AddInParameter(dbCommand, "SalePrice_U", DbType.Decimal, model.SalePrice_U);
            db.AddInParameter(dbCommand, "SalePrice_R", DbType.Decimal, model.SalePrice_R);
            db.AddInParameter(dbCommand, "RentPrice", DbType.Decimal, model.RentPrice);
            db.AddInParameter(dbCommand, "RentPrice_R", DbType.Decimal, model.RentPrice_R);
            db.AddInParameter(dbCommand, "HavRentContract", DbType.Boolean, model.HavRentContract);
            db.AddInParameter(dbCommand, "PayMode", DbType.AnsiString, model.PayMode);
            db.AddInParameter(dbCommand, "IsGroup", DbType.Boolean, model.IsGroup);
            db.AddInParameter(dbCommand, "BaseEquip", DbType.AnsiString, model.BaseEquip);
            db.AddInParameter(dbCommand, "OtherEquip", DbType.AnsiString, model.OtherEquip);
            db.AddInParameter(dbCommand, "Status", DbType.Int32, model.Status);
            db.AddInParameter(dbCommand, "Adddate", DbType.DateTime, model.Adddate);
            db.AddInParameter(dbCommand, "AddPersonId", DbType.Guid, model.AddPersonId);
            db.AddInParameter(dbCommand, "AddPerson", DbType.AnsiString, model.AddPerson);
            db.AddInParameter(dbCommand, "AddDepartId", DbType.Guid, model.AddDepartId);
            db.AddInParameter(dbCommand, "AddDepart", DbType.AnsiString, model.AddDepart);
            db.AddInParameter(dbCommand, "OprPersonId", DbType.Guid, model.OprPersonId);
            db.AddInParameter(dbCommand, "OprPerson", DbType.AnsiString, model.OprPerson);
            db.AddInParameter(dbCommand, "OprDepartId", DbType.Guid, model.OprDepartId);
            db.AddInParameter(dbCommand, "OprDepart", DbType.AnsiString, model.OprDepart);
            db.AddInParameter(dbCommand, "IsProtectPhone", DbType.Boolean, model.IsProtectPhone);
            db.AddInParameter(dbCommand, "DisplayPhone", DbType.AnsiString, model.DisplayPhone);
            db.AddInParameter(dbCommand, "IsProtectHouse", DbType.Boolean, model.IsProtectHouse);
            db.AddInParameter(dbCommand, "IsAutoProPhone", DbType.Boolean, model.IsAutoProPhone);
            db.AddInParameter(dbCommand, "IsAutoProHouse", DbType.Boolean, model.IsAutoProHouse);
            db.AddInParameter(dbCommand, "UpdateTime", DbType.DateTime, model.UpdateTime);
            db.AddInParameter(dbCommand, "ServiceTime", DbType.DateTime, model.ServiceTime);
            db.AddInParameter(dbCommand, "IsHot", DbType.Boolean, model.IsHot);
            db.AddInParameter(dbCommand, "IsHavekey", DbType.Boolean, model.IsHavekey);
            db.AddInParameter(dbCommand, "IsTrust", DbType.Boolean, model.IsTrust);
            db.AddInParameter(dbCommand, "IsMarked", DbType.Boolean, model.IsMarked);
            db.AddInParameter(dbCommand, "MarkCode", DbType.AnsiString, model.MarkCode);
            db.AddInParameter(dbCommand, "IsNeedTran", DbType.Boolean, model.IsNeedTran);
            db.AddInParameter(dbCommand, "RequestNum", DbType.Int32, model.RequestNum);
            db.AddInParameter(dbCommand, "InfoSource", DbType.AnsiString, model.InfoSource);
            db.AddInParameter(dbCommand, "Actuality", DbType.AnsiString, model.Actuality);
            db.AddInParameter(dbCommand, "BusinessKind", DbType.Int32, model.BusinessKind);
            db.AddInParameter(dbCommand, "Property", DbType.AnsiString, model.Property);
            db.AddInParameter(dbCommand, "TraceNum", DbType.Int32, model.TraceNum);
            db.AddInParameter(dbCommand, "HitNum", DbType.Int32, model.HitNum);
            db.AddInParameter(dbCommand, "Remarks", DbType.AnsiString, model.Remarks);
            db.AddInParameter(dbCommand, "IsHideHouse", DbType.Boolean, model.IsHideHouse);
            db.AddInParameter(dbCommand, "DetailAddress", DbType.AnsiString, model.DetailAddress);
          //  db.AddInParameter(dbCommand, "HouseBlock", DbType.AnsiString, model.HouseBlock);
            db.ExecuteNonQuery(dbCommand);

        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public static void Delete(Guid HouseId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from House_BaseInfo ");
            strSql.Append(" where HouseId=@HouseId ");
            Database db = DatabaseFactory.CreateDatabase(CONNECTSTRING);
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "HouseId", DbType.Guid, HouseId);
            db.ExecuteNonQuery(dbCommand);

        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public static Chenxin.Lib.House.Entity.House_BaseInfo GetModel(Guid HouseId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select HouseId,CityId,HouseCode,CommunityId,Community,BuildingId,BuildingName,Room,Address,Region,Block,CompleteYear,CustomerId,CustomerName,BuildingArea,HouseUse,BuildingType,Model_Room,CompanyId,CompanyName,Model_Hall,Model_Toilet,Model_Balcony,Total_Floor,Cur_Floor,Fitment,Direction,SalePrice_T,SalePrice_U,SalePrice_R,RentPrice,RentPrice_R,HavRentContract,PayMode,IsGroup,BaseEquip,OtherEquip,Status,Adddate,AddPersonId,AddPerson,AddDepartId,AddDepart,OprPersonId,OprPerson,OprDepartId,OprDepart,IsProtectPhone,DisplayPhone,IsProtectHouse,IsAutoProPhone,IsAutoProHouse,UpdateTime,ServiceTime,IsHot,IsHavekey,IsTrust,IsMarked,MarkCode,IsNeedTran,RequestNum,InfoSource,Actuality,BusinessKind,Property,TraceNum,HitNum,Remarks,IsHideHouse,DetailAddress,HouseBlock from House_BaseInfo ");
            strSql.Append(" where HouseId=@HouseId ");
            Database db = DatabaseFactory.CreateDatabase(CONNECTSTRING_SEARCH);
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "HouseId", DbType.Guid, HouseId);
            Chenxin.Lib.House.Entity.House_BaseInfo model = null;
            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                if (dataReader.Read())
                {
                    model = ReaderBind(dataReader);
                }
                dataReader.Close();
                dataReader.Dispose();
            }
            return model;
        }
        /// <summary>
        /// 获取一个实体
        /// </summary>
        /// <param name="where">查询条件</param>
        /// <returns></returns>
        public static Chenxin.Lib.House.Entity.House_BaseInfo GetModel(string where)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select HouseId,CityId,HouseCode,CommunityId,Community,BuildingId,BuildingName,Room,Address,Region,Block,CompleteYear,CustomerId,CustomerName,BuildingArea,HouseUse,BuildingType,Model_Room,CompanyId,CompanyName,Model_Hall,Model_Toilet,Model_Balcony,Total_Floor,Cur_Floor,Fitment,Direction,SalePrice_T,SalePrice_U,SalePrice_R,RentPrice,RentPrice_R,HavRentContract,PayMode,IsGroup,BaseEquip,OtherEquip,Status,Adddate,AddPersonId,AddPerson,AddDepartId,AddDepart,OprPersonId,OprPerson,OprDepartId,OprDepart,IsProtectPhone,DisplayPhone,IsProtectHouse,IsAutoProPhone,IsAutoProHouse,UpdateTime,ServiceTime,IsHot,IsHavekey,IsTrust,IsMarked,MarkCode,IsNeedTran,RequestNum,InfoSource,Actuality,BusinessKind,Property,TraceNum,HitNum,Remarks,IsHideHouse,DetailAddress,HouseBlock from House_BaseInfo ");
            strSql.AppendFormat(" where {0}",where);
            Database db = DatabaseFactory.CreateDatabase(CONNECTSTRING_SEARCH);
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            Chenxin.Lib.House.Entity.House_BaseInfo model = null;
            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                if (dataReader.Read())
                {
                    model = ReaderBind(dataReader);
                }
                dataReader.Close();
                dataReader.Dispose();
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public static DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select HouseId,CityId,HouseCode,CommunityId,Community,BuildingId,BuildingName,Room,Address,Region,Block,CompleteYear,CustomerId,CustomerName,BuildingArea,HouseUse,BuildingType,Model_Room,CompanyId,CompanyName,Model_Hall,Model_Toilet,Model_Balcony,Total_Floor,Cur_Floor,Fitment,Direction,SalePrice_T,SalePrice_U,SalePrice_R,RentPrice,RentPrice_R,HavRentContract,PayMode,IsGroup,BaseEquip,OtherEquip,Status,Adddate,AddPersonId,AddPerson,AddDepartId,AddDepart,OprPersonId,OprPerson,OprDepartId,OprDepart,IsProtectPhone,DisplayPhone,IsProtectHouse,IsAutoProPhone,IsAutoProHouse,UpdateTime,ServiceTime,IsHot,IsHavekey,IsTrust,IsMarked,MarkCode,IsNeedTran,RequestNum,InfoSource,Actuality,BusinessKind,Property,TraceNum,HitNum,Remarks,IsHideHouse,DetailAddress ");
            strSql.Append(" FROM House_BaseInfo ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            Database db = DatabaseFactory.CreateDatabase(CONNECTSTRING_SEARCH);
            return db.ExecuteDataSet(CommandType.Text, strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            Database db = DatabaseFactory.CreateDatabase(CONNECTSTRING);
            DbCommand dbCommand = db.GetStoredProcCommand("UP_GetRecordByPage");
            db.AddInParameter(dbCommand, "tblName", DbType.AnsiString, "House_BaseInfo");
            db.AddInParameter(dbCommand, "fldName", DbType.AnsiString, "ID");
            db.AddInParameter(dbCommand, "PageSize", DbType.Int32, PageSize);
            db.AddInParameter(dbCommand, "PageIndex", DbType.Int32, PageIndex);
            db.AddInParameter(dbCommand, "IsReCount", DbType.Boolean, 0);
            db.AddInParameter(dbCommand, "OrderType", DbType.Boolean, 0);
            db.AddInParameter(dbCommand, "strWhere", DbType.AnsiString, strWhere);
            return db.ExecuteDataSet(dbCommand);
        }*/
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public static DataSet GetList(int PageIndex, int PageSize, String OrderField, string TableName, string StrWhere, string FieldList, string TableFieldList, bool DoCount)
        {
            Database db = DatabaseFactory.CreateDatabase(CONNECTSTRING_SEARCH);
            DbCommand dbCommand = db.GetStoredProcCommand("PagerMultiTable");
            db.AddInParameter(dbCommand, "PageIndex", DbType.Int32, PageIndex);

            db.AddInParameter(dbCommand, "PageSize", DbType.Int32, PageSize);
            db.AddInParameter(dbCommand, "OrderField", DbType.AnsiString, OrderField);
            db.AddInParameter(dbCommand, "TableName", DbType.AnsiString, TableName);
            db.AddInParameter(dbCommand, "StrWhere", DbType.AnsiString, StrWhere);
            db.AddInParameter(dbCommand, "FieldList", DbType.AnsiString, FieldList);
            db.AddInParameter(dbCommand, "TableFieldList", DbType.AnsiString, TableFieldList);
            db.AddInParameter(dbCommand, "DoCount", DbType.Boolean, DoCount);
            return db.ExecuteDataSet(dbCommand);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public static DataSet GetListBySql(string strSQL)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(strSQL);
            Database db = DatabaseFactory.CreateDatabase("Chenxin_House_Search");
            return db.ExecuteDataSet(CommandType.Text, strSql.ToString());
        }

        //直接执行SQL语句
        public static bool ExecuteSQL(string strSQL)
        {
            Database db = DatabaseFactory.CreateDatabase("Chenxin_House_Search");
            int count = db.ExecuteNonQuery(CommandType.Text, strSQL);
            if (count > 0)
                return true;
            else
                return false;
        }

        /// <summary>
        /// 获得数据列表（比DataSet效率高，推荐使用）
        /// </summary>
        public static List<Chenxin.Lib.House.Entity.House_BaseInfo> GetListArray(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select HouseId,CityId,HouseCode,CommunityId,Community,BuildingId,BuildingName,Room,Address,Region,Block,CompleteYear,CustomerId,CustomerName,BuildingArea,HouseUse,BuildingType,Model_Room,CompanyId,CompanyName,Model_Hall,Model_Toilet,Model_Balcony,Total_Floor,Cur_Floor,Fitment,Direction,SalePrice_T,SalePrice_U,SalePrice_R,RentPrice,RentPrice_R,HavRentContract,PayMode,IsGroup,BaseEquip,OtherEquip,Status,Adddate,AddPersonId,AddPerson,AddDepartId,AddDepart,OprPersonId,OprPerson,OprDepartId,OprDepart,IsProtectPhone,DisplayPhone,IsProtectHouse,IsAutoProPhone,IsAutoProHouse,UpdateTime,ServiceTime,IsHot,IsHavekey,IsTrust,IsMarked,MarkCode,IsNeedTran,RequestNum,InfoSource,Actuality,BusinessKind,Property,TraceNum,HitNum,Remarks,IsHideHouse,DetailAddress,HouseBlock ");
            strSql.Append(" FROM House_BaseInfo ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            List<Chenxin.Lib.House.Entity.House_BaseInfo> list = new List<Chenxin.Lib.House.Entity.House_BaseInfo>();
            Database db = DatabaseFactory.CreateDatabase(CONNECTSTRING_SEARCH);
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            {
                while (dataReader.Read())
                {
                    list.Add(ReaderBind(dataReader));
                }
                dataReader.Close();
                dataReader.Dispose();
            }
            return list;
        }


        /// <summary>
        /// 对象实体绑定数据
        /// </summary>
        public static Chenxin.Lib.House.Entity.House_BaseInfo ReaderBind(IDataReader dataReader)
        {
            Chenxin.Lib.House.Entity.House_BaseInfo model = new Chenxin.Lib.House.Entity.House_BaseInfo();
            object ojb;
            ojb = dataReader["HouseId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.HouseId = new Guid(ojb.ToString());
            }
            ojb = dataReader["CityId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CityId = new Guid(ojb.ToString());
            }
            model.HouseCode = dataReader["HouseCode"].ToString();
            ojb = dataReader["CommunityId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CommunityId = new Guid(ojb.ToString());
            }
            model.Community = dataReader["Community"].ToString();
            ojb = dataReader["BuildingId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.BuildingId = new Guid(ojb.ToString());
            }
            model.BuildingName = dataReader["BuildingName"].ToString();
            model.Room = dataReader["Room"].ToString();
            model.Address = dataReader["Address"].ToString();
            model.Region = dataReader["Region"].ToString();
            model.Block = dataReader["Block"].ToString();
            ojb = dataReader["CompleteYear"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CompleteYear = (int)ojb;
            }
            ojb = dataReader["CustomerId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CustomerId = new Guid(ojb.ToString());
            }
            model.CustomerName = dataReader["CustomerName"].ToString();
            ojb = dataReader["BuildingArea"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.BuildingArea = Convert.ToDecimal(ojb);
            }
            model.HouseUse = dataReader["HouseUse"].ToString();
            model.BuildingType = dataReader["BuildingType"].ToString();
            ojb = dataReader["Model_Room"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.Model_Room = (int)ojb;
            }
            ojb = dataReader["CompanyId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CompanyId = new Guid(ojb.ToString());
            }
            model.CompanyName = dataReader["CompanyName"].ToString();
            ojb = dataReader["Model_Hall"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.Model_Hall = (int)ojb;
            }
            ojb = dataReader["Model_Toilet"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.Model_Toilet = (int)ojb;
            }
            ojb = dataReader["Model_Balcony"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.Model_Balcony = (int)ojb;
            }
            ojb = dataReader["Total_Floor"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.Total_Floor = (int)ojb;
            }
            ojb = dataReader["Cur_Floor"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.Cur_Floor = (int)ojb;
            }
            model.Fitment = dataReader["Fitment"].ToString();
            model.Direction = dataReader["Direction"].ToString();
            ojb = dataReader["SalePrice_T"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.SalePrice_T = (decimal)ojb;
            }
            ojb = dataReader["SalePrice_U"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.SalePrice_U = (decimal)ojb;
            }
            ojb = dataReader["SalePrice_R"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.SalePrice_R = (decimal)ojb;
            }
            ojb = dataReader["RentPrice"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.RentPrice = (decimal)ojb;
            }
            ojb = dataReader["RentPrice_R"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.RentPrice_R = (decimal)ojb;
            }
            ojb = dataReader["HavRentContract"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.HavRentContract = (bool)ojb;
            }
            model.PayMode = dataReader["PayMode"].ToString();
            ojb = dataReader["IsGroup"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.IsGroup = (bool)ojb;
            }
            model.BaseEquip = dataReader["BaseEquip"].ToString();
            model.OtherEquip = dataReader["OtherEquip"].ToString();
            ojb = dataReader["Status"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.Status = (int)ojb;
            }
            ojb = dataReader["Adddate"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.Adddate = (DateTime)ojb;
            }
            ojb = dataReader["AddPersonId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.AddPersonId = new Guid(ojb.ToString());
            }
            model.AddPerson = dataReader["AddPerson"].ToString();
            ojb = dataReader["AddDepartId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.AddDepartId = new Guid(ojb.ToString());
            }
            model.AddDepart = dataReader["AddDepart"].ToString();
            ojb = dataReader["OprPersonId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.OprPersonId = new Guid(ojb.ToString());
            }
            model.OprPerson = dataReader["OprPerson"].ToString();
            ojb = dataReader["OprDepartId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.OprDepartId = new Guid(ojb.ToString());
            }
            model.OprDepart = dataReader["OprDepart"].ToString();
            ojb = dataReader["IsProtectPhone"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.IsProtectPhone = (bool)ojb;
            }
            model.DisplayPhone = dataReader["DisplayPhone"].ToString();
            ojb = dataReader["IsProtectHouse"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.IsProtectHouse = (bool)ojb;
            }
            ojb = dataReader["IsAutoProPhone"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.IsAutoProPhone = (bool)ojb;
            }
            ojb = dataReader["IsAutoProHouse"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.IsAutoProHouse = (bool)ojb;
            }
            ojb = dataReader["UpdateTime"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.UpdateTime = (DateTime)ojb;
            }
            ojb = dataReader["ServiceTime"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ServiceTime = (DateTime)ojb;
            }
            ojb = dataReader["IsHot"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.IsHot = (bool)ojb;
            }
            ojb = dataReader["IsHavekey"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.IsHavekey = (bool)ojb;
            }
            ojb = dataReader["IsTrust"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.IsTrust = (bool)ojb;
            }
            ojb = dataReader["IsMarked"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.IsMarked = (bool)ojb;
            }
            model.MarkCode = dataReader["MarkCode"].ToString();
            ojb = dataReader["IsNeedTran"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.IsNeedTran = (bool)ojb;
            }
            ojb = dataReader["RequestNum"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.RequestNum = (int)ojb;
            }
            model.InfoSource = dataReader["InfoSource"].ToString();
            model.Actuality = dataReader["Actuality"].ToString();
            ojb = dataReader["BusinessKind"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.BusinessKind = (int)ojb;
            }
            model.Property = dataReader["Property"].ToString();
            ojb = dataReader["TraceNum"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.TraceNum = (int)ojb;
            }
            ojb = dataReader["HitNum"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.HitNum = (int)ojb;
            }
            model.Remarks = dataReader["Remarks"].ToString();
            ojb = dataReader["IsHideHouse"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.IsHideHouse = (bool)ojb;
            }
            model.DetailAddress = dataReader["DetailAddress"].ToString();
            model.HouseBlock = dataReader["HouseBlock"].ToString();
            return model;
        }

        #endregion  成员方法
    }
}

